//
//  SKLoginView.m
//  aURobot
//
//  Created by cdong on 16/2/17.
//  Copyright © 2016年 cdong. All rights reserved.
//

#import "SKLoginView.h"

@implementation SKLoginView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}

- (void)loadNagavitionViewWithString:(NSString *)nameString{
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 375*matchW, 20)];
    statusBarView.backgroundColor=[RGBColorEncapsulation colorWithRGB:0xffffff alpha:0.1];
    [self addSubview:statusBarView];
    UIView *navigationV = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 375*matchW, 44)];
    navigationV.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xffffff alpha:0.1];
    [self addSubview:navigationV];
    UILabel *navigationVL = [[UILabel alloc]initWithFrame:CGRectMake(((self.frame.size.width - 100)/2), 0, 100, 44)];
    navigationVL.text = nameString;
    navigationVL.textAlignment = NSTextAlignmentCenter;
    navigationVL.textColor = [RGBColorEncapsulation colorWithRGB:0xf8f8f8 alpha:1];
    navigationVL.font = [UIFont systemFontOfSize:19];
    [navigationV addSubview:navigationVL];
}

- (void)setUp{
    [self setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_login"]]];
    [self loadNagavitionViewWithString:@"登录"];
    self.iconImageV = [[UIImageView alloc]initWithFrame:CGRectMake((12+13.5)*matchW, (17+15)*matchH+44+20, 26*matchW, 26*matchH)];
    self.iconImageV.image = [UIImage imageNamed:@"icon_user"];
    [self addSubview:self.iconImageV];
    self.userNameTF = [[UITextField alloc]initWithFrame:CGRectMake(65*matchW, 17*matchH+20+44, self.frame.size.width - 53*matchW - 12*matchW, 60*matchH)];
    self.userNameTF.textColor = [RGBColorEncapsulation colorWithRGB:0xbab9ba
                                                              alpha:1];
    self.userNameTF.placeholder = @"请输入用户名或手机号";
    if ([self.userNameTF respondsToSelector:@selector(setAttributedPlaceholder:)]) {
        UIColor *color = [RGBColorEncapsulation colorWithRGB:0xbab9ba alpha:1];
        UIFont *font = [UIFont systemFontOfSize:15];
        self.userNameTF.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"请输入用户名或手机号" attributes:@{NSForegroundColorAttributeName:color,NSFontAttributeName:font}];
    }
    [self addSubview:self.userNameTF];
    self.fillV = [[UIView alloc]initWithFrame:CGRectMake(12*matchW, CGRectGetMaxY(self.userNameTF.frame), self.frame.size.width - 24*matchW, 1*matchH)];
    self.fillV.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x302f30 alpha:1];
    [self addSubview:self.fillV];
    self.pawImageV = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.iconImageV.frame), CGRectGetMaxY(self.fillV.frame) + 15, CGRectGetWidth(self.iconImageV.frame), CGRectGetHeight(self.iconImageV.frame))];
    self.pawImageV.image = [UIImage imageNamed:@"icon_lock"];
    [self addSubview:self.pawImageV];
    self.pawTF = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.userNameTF.frame), CGRectGetMaxY(self.fillV.frame), CGRectGetWidth(self.userNameTF.frame), CGRectGetHeight(self.userNameTF.frame))];
    self.pawTF.textColor = [RGBColorEncapsulation colorWithRGB:0xbab9ba alpha:1];
    self.pawTF.placeholder = @"请输入密码";
    self.pawTF.secureTextEntry = YES;
    if ([self.pawTF respondsToSelector:@selector(setAttributedPlaceholder:)]) {
        UIColor *color = [RGBColorEncapsulation colorWithRGB:0xbab9ba alpha:1];
        UIFont *font = [UIFont systemFontOfSize:15];
        self.pawTF.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"请输入密码" attributes:@{NSForegroundColorAttributeName:color,NSFontAttributeName:font}];
    }
    [self addSubview:self.pawTF];
    self.pawBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.pawBtn.frame = CGRectMake(CGRectGetMaxX(self.userNameTF.frame) - 18*matchW - 30*matchW, CGRectGetMinY(self.pawImageV.frame)+4*matchH, 26*matchW, 26*matchH);
    [self.pawBtn setBackgroundImage:[UIImage imageNamed:@"icon_eye"] forState:UIControlStateNormal];
    [self addSubview:self.pawBtn];
    self.fillV2 = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.fillV.frame), CGRectGetMaxY(self.pawTF.frame), CGRectGetWidth(self.fillV.frame), CGRectGetHeight(self.fillV.frame))];
    self.fillV2.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x302f30 alpha:1];
    [self addSubview:self.fillV2];
    self.loginBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.loginBtn.userInteractionEnabled = NO;
    self.loginBtn.frame = CGRectMake(12*matchW, CGRectGetMaxY(self.fillV2.frame)+30*matchH, self.frame.size.width - 24*matchH, 45*matchH);
    self.loginBtn.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xcc222a alpha:1];
    [self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    self.loginBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.loginBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:.5] forState:UIControlStateNormal];
    [self.loginBtn.layer setMasksToBounds:YES];
    [self.loginBtn.layer setCornerRadius:3];
    [self addSubview:self.loginBtn];
    self.retrievePwdBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.retrievePwdBtn.frame = CGRectMake(30*matchW, CGRectGetMaxY(self.loginBtn.frame)+20*matchH, 70, 30);
    [self.retrievePwdBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
    self.retrievePwdBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.retrievePwdBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
    [self addSubview:self.retrievePwdBtn];
    self.registerBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.registerBtn.frame = CGRectMake(self.frame.size.width - 30*matchW - 36*matchW, CGRectGetMinY(self.retrievePwdBtn.frame), 36*matchW, CGRectGetHeight(self.retrievePwdBtn.frame));
    [self.registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    [self.registerBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x7e7e7d alpha:1] forState:UIControlStateNormal];
    self.registerBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.registerBtn];
}

@end
